package com.yuanqi.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuanqi.pojo.Employee;
import com.yuanqi.service.EmployeeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/sales/employee")
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    // 简单下拉：支持按姓名关键词筛选、仅在职
    @GetMapping("/options")
    public List<Employee> options(@RequestParam(required = false) String keyword) {
        LambdaQueryWrapper<Employee> qw = new LambdaQueryWrapper<>();
        qw.eq(Employee::getStatus, 1);
        if (keyword != null && !keyword.trim().isEmpty()) {
            qw.like(Employee::getEmployeeName, keyword.trim());
        }
        qw.select(Employee::getId, Employee::getEmployeeName);
        return employeeService.list(qw);
    }
}


